home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / DSPanic / PatchItAsm.s < prev    next >
Encoding:
Text File  |  2001-06-23  |  1.9 KB  |  86 lines

  1. /*
  2.  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  *
  6.  * The contents of this file constitute Original Code as defined in and
  7.  * are subject to the Apple Public Source License Version 1.1 (the
  8.  * "License").  You may not use this file except in compliance with the
  9.  * License.  Please obtain a copy of the License at
  10.  * http://www.apple.com/publicsource and read it before using this file.
  11.  *
  12.  * This Original Code and all software distributed under the License are
  13.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17.  * License for the specific language governing rights and limitations
  18.  * under the License.
  19.  *
  20.  * @APPLE_LICENSE_HEADER_END@
  21.  */
  22. /*
  23.  * MPEnabler - An example of patching funtions in the Mac OS X Kernel
  24.  *
  25.  * Yes, I know that I said you don't patch functions in kernel,
  26.  * but you should remember what your mother used to say,
  27.  *
  28.  *   "Do and I say, not as I do."
  29.  * 
  30.  * Josh de Cesare, MacHack 2000
  31.  */
  32.  
  33.  
  34. #include <ppc/asm.h>
  35.  
  36.     .globl    _PatchItHelper
  37.  
  38. _PatchItHelper:
  39.     // Create a stack frame.
  40.     // Don't squash r0.
  41.     stmw    r28,    -0x10(r1)
  42.     mflr    r28
  43.     stw    r28,    0x8(r1)
  44.     stwu    r1,    -0x50(r1)
  45.     
  46.     // Save the patch pointer
  47.     mr    r28,    r0
  48.     
  49.     // Save arg0 in the patch data.
  50.     stw    r3,    0x0(r28)
  51.     
  52.     // Call the new function where arg0
  53.     // is the patch pointer.
  54.     lwz    r3,    0x8(r28)
  55.     mtctr    r3
  56.     mr    r3,    r28
  57.     bctrl
  58.     
  59.     // Clean up the stack frame.
  60.     addi    r1,    r1,    0x50
  61.     lwz    r0,    0x8(r1)
  62.     mtlr    r0
  63.     lmw    r28,    -0x10(r1)
  64.     blr
  65.  
  66.  
  67.     .globl _PatchItStub
  68.     
  69. _PatchItStub:
  70.     lis    r0,        0
  71.     ori    r0,    r0,    0
  72.     mtctr   r0
  73.     lis    r0,        0
  74.     ori    r0,    r0,    0
  75.     bctr
  76.     
  77.     .globl    _PatchItFlush
  78.     
  79. _PatchItFlush:
  80.     dcbst    0,    r3
  81.     sync
  82.     icbi    0,    r3
  83.     sync
  84.     isync
  85.     blr
  86.